package history.study.array;

// 367. 有效的完全平方数:https://leetcode-cn.com/problems/valid-perfect-square/
public class LeetCode_367 {
    // 二分查找求解
    public boolean isPerfectSquare(int num) {
        if (num<=0) return false;
        long left = 1, right = num;
        while (left <= right) {
            long mid = left + ((right-left)>>1);
            long midResult = mid*mid;
            if (midResult>num){
                right = mid-1;
            } else if (midResult<num) {
                left = mid+1;
            } else {
                return true;
            }
        }
        return false;
    }
}
